//
//  YWSelectTimeUnitTableViewController.m
//  maintain
//
//  Created by Kyo on 16/10/11.
//  Copyright © 2016年 ewin. All rights reserved.
//

#import "YWSelectTimeUnitTableViewController.h"
#import "UIColor+CustomColors.h"
#import "YWMacro.h"

@interface YWSelectTimeUnitTableViewController ()

@end

@implementation YWSelectTimeUnitTableViewController
- (instancetype)init{
    return [super  initWithStyle:UITableViewStyleGrouped];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = NSLocalizedString(@"selectUnit", nil);
    self.view.backgroundColor = [UIColor customBackgroudColor];
    
    self.tableView.rowHeight = 44;
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [self.unitArray count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *reuseIdentifier = @"selectUnitReuseIdentifier";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier];
        cell.textLabel.font = kContentFont;
    }
    NSString *unit = self.unitArray[indexPath.row];
    cell.textLabel.text = unit;
    if ([unit isEqualToString:self.currentUnit]) {
        cell.accessoryType = UITableViewCellAccessoryCheckmark;
    }else{
        cell.accessoryType = UITableViewCellAccessoryNone;
    }
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if ([self.delegate respondsToSelector:@selector(popSelectTimeUnit:)]) {
        NSString *unit = self.unitArray[indexPath.row];
        [self.delegate popSelectTimeUnit:unit];
        [self.navigationController popViewControllerAnimated:YES];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
